import { Component, OnInit } from '@angular/core'
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop'

@Component({
  selector: 'Role-Auth-Map',
  templateUrl: './role-auth-map.component.html',
  styleUrls: ['./role-auth-map.component.less']
})
export class RoleAuthMapComponent implements OnInit {
  activedRoleIndex = 0
  roles = [
    '超级管理员',
    '管理员',
    '门户用户',
  ]
  granted = [
    '公告管理',
    '公告发布',
    '组织创建',
    '组织查看',
    '组织编辑'
  ]

  ungranted = [
    '组织删除',
    '公告删除',
    '组织成员增加',
    '组织成员增加',
  ]
  constructor() { }
  ngOnInit(): void { }

  drop(event: CdkDragDrop<string[]>) {
    if (event.previousContainer === event.container) {
      moveItemInArray(event.container.data, event.previousIndex, event.currentIndex)
    } else {
      transferArrayItem(event.previousContainer.data,
        event.container.data,
        event.previousIndex,
        event.currentIndex)
    }
  }

  activeRole(index: number) {
    this.activedRoleIndex = index
    this.granted = [
      '公告管理',
      '公告发布',
      '组织创建',
      '组织查看',
      '组织编辑'
    ]

    this.ungranted = [
      '组织删除',
      '公告删除',
      '组织成员增加',
      '组织成员增加',
    ]
  }
}
